package org.cytoscape.myapp.cytoscape_app_v1.internal.grupos;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupFactory;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.group.events.GroupCollapsedEvent;
import org.cytoscape.group.events.GroupCollapsedListener;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyEdge.Type;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.myapp.cytoscape_app_v1.internal.helpers.ViewUtil;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.view.presentation.property.BasicVisualLexicon;

public class Grupos  {

	private HashMap<String, List<CyNode>> grupos;
	private CyGroupManager mnGroup;
	private CyGroupFactory facGroup;
	private CyNetwork network;
	
	
	
	public Grupos(CyGroupManager mnGroup, CyGroupFactory facGroup, CyNetwork network){
		this.mnGroup = mnGroup;
		this.facGroup = facGroup;
		this.network = network;
		this.grupos = new HashMap<String, List<CyNode>>();
	
	}
	
	public void addNode(CyNode node, String nameGroup){
		List<CyNode> grupoChoose = this.grupos.get(nameGroup);
		if (grupoChoose == null)
		{
			this.grupos.put(nameGroup,new Vector<CyNode>());
			List<CyNode> listNodes = this.grupos.get(nameGroup);
			listNodes.add(node);
		}	
		else{
				grupoChoose.add(node);
			}
		
	}
	
	public void createAndRegisterAllGroups(){
		
		Set<String> keys = grupos.keySet();
		for(String key:keys){
			CyNode nodeDad = network.addNode();
			network.getRow(nodeDad).set(CyNetwork.NAME, key);
			CyGroup newGroup = facGroup.createGroup(network,nodeDad,false);
			mnGroup.addGroup(newGroup);
			List<CyNode> listNode = grupos.get(key);
			newGroup.addNodes(listNode);
		}
		
	}

}
